import BASE_URL from './env.js' //引入接口共用地址

export const requestInfo = (options) => {
	// uni.showLoading({
	// 	title: '正在加载...',
	// 	mask: true, //是否显示透明蒙层，防止触摸穿透，默认：false
	// })
	return new Promise((resolve, reject) => {
		let token =uni.getStorageSync('userInfo').token
		console.log('token', token)
		const header = {
			// 'Content-Type': 'application/x-www-form-urlencoded',
			'Content-Type': 'application/json',
			platform:'WechatMiniProgram',
			// token:`Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9waW5nYmFub3JkZXIuY25cL2FwaVwvdjFcL3VzZXJfbG9naW4iLCJpYXQiOjE3NTI1NDYxMTUsImV4cCI6MTc1MjY3NTcxNSwibmJmIjoxNzUyNTQ2MTE1LCJqdGkiOiJrU0V6aFNMSUhjampiWDJnIiwic3ViIjoxMjQ1LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.kPL5TjvvGZSHZLEWqNUu9NO8EHb111VSBqoo_2B6iRA`,
			token: `${token}`
		}
		// console.log(BASE_URL + options.url);
		uni.request({
			url: BASE_URL + options.url, //接口地址：前缀+方法中传入的地址
			method: options.method || 'GET', //请求方法：传入的方法或者默认是“GET”
			data: options.data || {}, //传递参数：传入的参数或者默认传递空集合
			header,
			success: (res) => {

				// console.log('请求的东西', res, res.data.data)
				resolve(res.data)

				// uni.hideLoading()
			},
			// 这里的接口请求，如果出现问题就输出接口请求失败
			fail: (err) => {
				console.log(err, '错误参数')
				console.log(BASE_URL + options.url);
				// uni.hideLoading()
				reject(err)
			}
		})
	})
}